<?php abstract class Collection implements Iterator {
	protected $Dir = '';                    // Children should define it
	protected $Elements = array ();

	public function __construct ($Amount = -1) {
		if ($Amount) {
			foreach (glob ($this->Dir ().'*') as $Filename) {
				$Element = $this->CreateElement (basename ($Filename));
				$this->Elements [$Element->Timestamp] = $Element;
			}
			krsort ($this->Elements);
			($Amount > 0) and $this->Elements = array_slice ($this->Elements, 0, $Amount);
		}
	}

	protected function Dir () {return (PREFIX.$this->Dir.'/');}

	public function rewind () {return (reset ($this->Elements));}
	public function current () {return (current ($this->Elements));}
	public function key () {return (key ($this->Elements));}
	public function next () {return (next ($this->Elements));}
	public function valid () {return ($this->current () !== FALSE);}
	public function count () {return (count ($this->Elements));}

	public function CreateElement ($Id) {return (new Element ($this->Dir ().$Id));}
	public function MostRecent () {
		if ($this->Elements) {
			$Entry = $this->rewind ();
			return ($Entry->Timestamp);
		} else return (0);
	}
} ?>